import { simpleCall, simpleDelCall, simplePostCall, simplePutCall } from '../utils/Action';
import type { CveCreateInput, CveSimple, CveUpdateInput, SearchPaginationInput } from '../utils/api-types';

const CVE_URI = '/api/cves';

export const searchCves = (searchPaginationInput: SearchPaginationInput) => {
  const data = searchPaginationInput;
  const uri = `${CVE_URI}/search`;
  return simplePostCall(uri, data);
};

export const fetchCve = (cveId: string) => {
  const uri = `${CVE_URI}/${cveId}`;
  return simpleCall(uri);
};

export const fetchCveByExternalId = (cveId: string) => {
  const uri = `${CVE_URI}/external-id/${cveId}`;
  return simpleCall(uri);
};

export const addCve = (data: CveCreateInput) => {
  return simplePostCall(`${CVE_URI}`, data);
};

export const updateCve = (cveId: CveSimple['cve_id'], data: CveUpdateInput) => {
  const uri = `${CVE_URI}/${cveId}`;
  return simplePutCall(uri, data);
};

export const deleteCve = (cveId: CveSimple['cve_id']) => {
  const uri = `${CVE_URI}/${cveId}`;
  return simpleDelCall(uri);
};
